﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using AjaxControlToolkit;

namespace Hired
{
    public partial class empViewJob : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Job> jobsToDisplay = new List<Job>();
            string company = Request.QueryString["company"];
            List<object> jobApplicationsToDisplay = new List<object>();

            if (company != null)
            {
                jobsToDisplay = DBJob.retrieveJobByCompany(company);
                gvViewJobs.DataSource = jobsToDisplay;
                gvViewJobs.DataBind();

                jobApplicationsToDisplay = returnJobApplications(DBJobApplication.RetrieveJobApplicationByCompany(company));
                gvJobApplications.DataSource = jobApplicationsToDisplay;
                gvJobApplications.DataBind();
            }

        }

        public List<object> returnJobApplications(List<JobApplication> jobApplications)
        {
            using (hireddbEntities db = new hireddbEntities())
            {
                return
                    (from ja in jobApplications
                     join js in db.JobseekerAccounts
                     on ja.JAccountID equals js.JAccountID
                     select new
                     {
                         Username = js.Username,
                         Contents = ja.Contents,
                         Resume = ja.ResumeAddress,
                         Title = ja.Job.Title
                     }).ToList<object>();

            }
        }
       
        protected void gvViewJobs_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DBJob.DeleteJobById(e.CommandArgument.ToString());
            }
        }
    }
}